'''
作业：添加图片后，使用上传的图片添加车辆
车牌号，可以用字符串+随机数拼接
'''
import  random

import requests

path = "C:\\Users\Administrator\Desktop\\1234.png"  # 要上传的文件
url = "http://192.168.150.84:8088/carRental/file/uploadFile.action"
with open(path, mode='rb') as f:
    fs = {"mf": (path, f,"image/png")}  #三元组Content-Type表示上传文件的类型
    r = requests.post(url, files=fs)
    print(r.text)
    img = r.json()['data']['src'] #文件路径
    print(img)


# http://192.168.150.84:8088/carRental/bus/toCustomerManager.action
#s = requests.Session()
url = "http://192.168.150.84:8088/carRental/car/addCar.action"


for i in range(24,25):



    cs = {
    "carimg": img,
    "carnumber":"陕F%d"%random.randint(12345,98765),
    "cartype"	:"凯迪拉克%d"%i,
    "color":	random.choice(["黑色","白色","灰色"]),
    "deposit":"1000%d"%i,
    "description"	:"这是一辆车%d"%i,
    "isrenting":	random.randint(0,1),
    "price":"567895%d"%i,
    "rentprice"	:"200%d"%i
    }
    r= requests.post(url,params=cs)
    print(r.text)




